'use strict';

angular.module('com.dcos.app').controller('UserCenterDetailController',function($window,$scope,$uibModalInstance,user,type,reload,UserCenterService) {
  var vm = this;

  vm.dept_id=$window.sessionStorage.getItem("curDept_Id");
  vm.usertype=$window.sessionStorage.getItem("curUserType");
  vm.userTypeData=[];
  if(vm.usertype=="1")
    vm.userTypeData=[{"type_id":"0","type_name":"普通用户"},{"type_id":"1","type_name":"项目管理员"}];
  else if(vm.usertype=="2")
    vm.userTypeData=[{"type_id":"0","type_name":"普通用户"},{"type_id":"1","type_name":"项目管理员"},{"type_id":"2","type_name":"超级管理员"}];

  if(user)
    vm.user=user;
  else
    vm.user={
      "userid":"",
      "username":"",
      "password":"",
      "confirm_password":"",
      "usertype":"0",
      "dept_id":vm.dept_id,
      "status":"1"
    };
    
  vm.user.confirm_password=vm.user.password;

  vm.ok = function () {
    if(type=="create"){
      UserCenterService.save(vm.user).then(function (response) {
          reload();
          $uibModalInstance.dismiss('cancel');
      });
    }else{
      UserCenterService.update(vm.user).then(function (response) {
          reload();
          $uibModalInstance.dismiss('cancel');
      });
    }
  }

  vm.cancel = function () {
    $uibModalInstance.dismiss('cancel');
  };
  
});
